﻿#region Copyright
//       Copyright (c) 2009 - Antoine Jaussoin - http://www.jaussoin.com/blog/
// 
//        This program is free software: you can redistribute it and/or modify
//        it under the terms of the GNU General Public License as published by
//        the Free Software Foundation, either version 3 of the License, or
//        (at your option) any later version.
// 
//        This program is distributed in the hope that it will be useful,
//        but WITHOUT ANY WARRANTY; without even the implied warranty of
//        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//        GNU General Public License for more details.
// 
//        You should have received a copy of the GNU General Public License
//        along with this program.  If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;

namespace FT.Architecture.Utils.ExtensionMethods
{
    /// <summary>
    /// Extension Methods for Enumerations
    /// </summary>
    public static class EnumerationExtensions
    {
        /// <summary>
        /// Transform a string such as "DailyAbsoluteReturn" to "Daily Absolute Return".
        /// Very useful to get a friendly display of the value of an enumeration for example.
        /// </summary>
        /// <param name="enumeration"></param>
        /// <returns></returns>
        public static string GetFriendlyDisplay(this Enum enumeration)
        {
            return GetFriendlyDisplay(enumeration, EnumerationStyle.UpperAndLowerCaseNoUnderscore);
        }

        /// <summary>
        /// Transform a string such as "DailyAbsoluteReturn" or "DAILY_ABSOLUTE_RETURN" to "Daily Absolute Return".
        /// Very useful to get a friendly display of the value of an enumeration for example.
        /// </summary>
        /// <param name="enumeration"></param>
        /// <param name="style">Style of the enumeration</param>
        /// <returns></returns>
        public static string GetFriendlyDisplay(this Enum enumeration, EnumerationStyle style)
        {
            string s = enumeration.ToString();
            return s.GetFriendlyDisplay(style);
        }
    }

    /// <summary>
    /// Style of the enumeration items, used to guess a friendly display
    /// </summary>
    public enum EnumerationStyle
    {
        /// <summary>
        /// Upper and lower case, with no underscore, such as :
        /// "MyNameIsBob" or "Bob"
        /// </summary>
        UpperAndLowerCaseNoUnderscore,
        /// <summary>
        /// Upper case only, with underscore between each works :
        /// "MY_NAME_IS_BOB" or "BOB"
        /// </summary>
        UpperCaseWithUnderscore
    }
}